home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_360 / uucp / uucp0.lzh / src / lib / getenv.c < prev    next >
C/C++ Source or Header  |  1990-04-04  |  1KB  |  64 lines

  1.  
  2. /*
  3.  *  GETENV.C
  4.  *
  5.  *  $Header: Beta:src/uucp/src/lib/RCS/getenv.c,v 1.1 90/02/02 12:08:18 dillon Exp Locker: dillon $
  6.  *
  7.  *  Lattice's screws up.
  8.  *
  9.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  10.  */
  11.  
  12. #include "protos.h"
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include "config.h"
  17.  
  18. Prototype char *gettmpenv(const char *);
  19. Prototype char *getenv(const char *);
  20.  
  21. char *
  22. gettmpenv(id)
  23. const char *id;
  24. {
  25.     static char *buf;
  26.     static char *res = NULL;
  27.     long fh;
  28.     long len;
  29.  
  30.     buf = malloc(strlen(id) + 8);
  31.     sprintf(buf, "ENV:%s", id);
  32.     fh = Open(buf, 1005);
  33.     free(buf);
  34.     if (fh) {
  35.     Seek(fh, 0L, 1);
  36.     len = Seek(fh, 0L, -1);
  37.     if (len < 0) {
  38.         Close(fh);
  39.         return(NULL);
  40.     }
  41.     if (res)
  42.         free(res);
  43.     res = malloc(len + 1);
  44.     Read(fh, res, len);
  45.     Close(fh);
  46.     res[len] = 0;
  47.     return(res);
  48.     }
  49.     return(NULL);
  50. }
  51.  
  52. char *
  53. getenv(id)
  54. const char *id;
  55. {
  56.     char *res = gettmpenv(id);
  57.     char *perm = NULL;
  58.  
  59.     if (res)
  60.     perm = strdup(res);
  61.     return(perm);
  62. }
  63.  
  64.